# Runge Kutta for Disk
from math import *
from Constants import *
from Init_Cond import m_pdisk, r_pdisk, rho_sat
from Lists import Sat_M, Sat_Rad, Sat_r, Sat_v, sigma

L = log((2 + sqrt(3))/(2 - sqrt(3)))

def f(msat, loc, e, i, c):      #dm_dt equation from Thommes (2003)
    return c*sigma[loc]*msat**(4./3.)/(e*sqrt(Sat_r[i]))

def sat(i, loc, M, deltat):  #given a satellite identifier, calculates the the new mass and velocity of the satellite

    c = 6.*pi**(2./3.)*(3./(4.*rho_sat))**(1./3.)*sqrt(G/M)     #constant, for dm_dt

    #this is a runge kutta scheme
    k1 = f(Sat_M[i], loc, e, i, c)
    k2 = f(Sat_M[i]+(deltat/2.)*k1, loc, e, i, c)
    k3 = f(Sat_M[i]+(deltat/2.)*k2, loc, e, i, c)
    k4 = f(Sat_M[i]+deltat*k3, loc, e, i, c)

    msat = Sat_M[i] + (deltat/6.)*(k1 + 2.*k2 + 2.*k3 + k4)     #new mass of the satellite

    return msat

